<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <title>Title</title>
        <link rel="stylesheet" href="css/personal.css">
        <link rel="stylesheet" href="css/Test.css">
        <link rel="stylesheet" href="../public_css/public_simulation.css">

        <script src="../jquery.min.js"></script>
        <script src="../layer.js"></script>
        <script>
            $(function(){
                //设置根元素字体
                setFontSize()
            });
            //设置根元素字体
            var win = window,
                doc = document;
            function setFontSize() {
                var winWidth = $(window).width();

                //750这个数字是根据你的设计图的实际大小来的，所以值具体根据设计图的大小
                var size = (winWidth /640) * 100;
                doc.documentElement.style.fontSize = (size < 100 ? size : 100) + 'px';
            }

        </script>
    </head>

    <body>
        <div class="nav"><!--头部-->
            <header class="public_simulation">
                <div class="public_simulation_return" onclick="history.back(-1)">
                    <img src="../public_img/return.png" alt="">
                </div>
                <div class="public_simulation_title">
                    <span >科一模拟</span>
                    <span class="time"></span>
                </div>
                <div class="public_simulation_assignment submit"  onclick="sub()">
                    交卷
                </div>
            </header>
        </div><!--nav结束-->


        <div class="main" ><!--练习题开始-->

            <script>var wrap = $(".print");var item = $(".print img").attr("src");if(item=""){wrap.css("display","none")}else{wrap.css("display","block")}</script>

        </div>
        <!--底部-->
        <div id="navigation">
            <!--收藏题弹出部分-->
            <div class="collects">
                <section class="collects_title">
                    <div class="collects_title_left" id="collection" >
                        <img src="img/start.png" >
                        <span style="color: #f49d43" title_id="">收藏</span>
                    </div>

                    <div class="collects_title_right">
                        <figure>
                            <img src="img/gou.png" >
                            <span style="color:#f49d43;"></span>
                        </figure>
                        <figure>
                            <!--<img src="img/cha.png" >-->
                            <span style="color: #fc143b"></span>
                        </figure>
                        <figure>
                            <!--<img src="img/si.png" >-->
                            <span class="index">1</span>/<i style="color: #999999;font-style:normal">100</i>
                        </figure>
                    </div>
                </section>
            </div>
        </div>

        <script src="js/personal.js"></script>
        <script>
            var title=0;
            var falseAnswer=0;
            var a=0;//获取用户做到第几题了  $.ajax
            var titleID=a;
            var M=44;
            var S=59;
            var token=localStorage.phone;
            var id=Array();
            var cid=Array();
            function time(S,M){
                var flase=true;
                if(M=='00' && S=='00'){
                    flase=false;
                }
                $('.time').html(M+':'+S);
                if(S=='00'){
                    S=59;
                    M=M-1;
                }
                else if(S<=10){
                    S='0'+(parseInt(S)-1);
                }
                else{
                    S=S-1;
                }
                if(M<10){
                    M='0'+parseInt(M);
                }

                if(flase){
                    setTimeout(function () {
                        time(S,M);
                    },1000)
                }else{
                    alert('交卷');
                    sub();
                }

            }
            $(function () {
                time(S,M);
                var type='test';
                $.ajax({
                    url:"https://newapp.icandrive.cn/api/demo.php",
                    type:'post',
                    dataType:'json',
                    data:{page:a,typeT:type,token:token},
                    success:function(data){
                        if(data.status==200){
                            var b=a+1;
                            $(data.list).each(function () {
                                var imgTemp='';
                                var wrongrate=(Math.round(this.wrongrate*10000))/100+'%';
                                if(this.img!=null && this.img!=''){
                                    imgTemp="<div class='print'><img src='../img/"+this.img+"'></div>";
                                }
                                var temp='';
                                if($.trim(this.type)!='Type:0'){
                                    var title_type='选择题';

                                    temp="<li><span class='but'>A</span><span>"+this.a+"</span></li><li><span class='but'>B</span><span>"+this.b+"</span></li><li><span class='but'>C</span><span>"+this.c+"</span></li><li><span class='but'>D</span><span>"+this.d+"</span></li>";
                                }
                                else{
                                    var title_type='判断题';
                                    temp="<li><span class='but'>A</span><span>"+this.a+"</span></li><li><span class='but'>B</span><span>"+this.b+"</span></li>";
                                }
                                $('.main').append("<div class='t main_wrap main_wrap1'><a class='select'><p>"+title_type +"</p><p><span>收藏</span><span>233</span></p><p><span>错误率</span><span>"+wrongrate+"</span></p></a><div class='topic'>"+'<span> '+b+'、'+this.title+"</span>"+imgTemp+"</div><div class='key'><ul>"+temp+"</ul><button class='sure' id='"+this.id+"'>确定</button></div><div class='analysis' style='display: none'><span>题目解析：<i class='answer'>"+this.answer+"</i></span><p>"+this.content+"</p></div><button id='"+this.id+"' class='next' style='display: none'>下一题</button></div>")
                                b++;
                            });
                        }
                        $('.main .t').hide();
                        $('.main>div').eq(0).show();
                        $("#collection span").attr('title_id',$('.main>div').eq(0).find('.next').prop('id'));
                    }
                })
            })
            var text=$('#collection span').html()
            if(text=='收藏'){
                $("#collection").on('click', function () {
                    var id=$('#collection span').attr('title_id');
                    var type='collection';
                    $.ajax({
                        url:"https://newapp.icandrive.cn/api/title_select.php",
                        data:{token:token,type:type,title_id:id},
                        dataType:'json',
                        type:'post',
                        success: function (data) {
                            if(data.status==200){
                                layer.msg('收藏成功');
                            }
                            else if(data.status==300){
                                layer.msg('已经收藏过了');
                            }
                        },
                        error: function () {
                            layer.msg('系统繁忙');
                        }
                    })
                })
            }
            //下一题
            $(".main").on('click','.next',function(){
                var id=$(this).parent().next().find('.next').attr('id');
                $('#collection span').attr('title_id',id);
                $('#collection span').html('收藏');
                titleID++;
                var count = $(this).parent().parent().find('.t').length;
                var index = $(this).parent().index()+1;

                $(this).parent().hide();
                $(this).parent().next().show();
                $('.index').html(index);
            });
            //选题

            $('.main').on('click','.but', function () {
                if($(this).css('backgroundColor')!='rgba(0, 0, 0, 0)'){
                    $(this).css({
                        backgroundColor:'rgba(0, 0, 0, 0)',
                        color:'black'
                    });
                }
                else{
                    $(this).css({
                        backgroundColor:'green',
                        color:'white'
                    });

                }

            });
            $('.main').on('click','.sure', function () {

                var str='';
                $(this).parent().find('.but').each(function () {
                    if($(this).css('backgroundColor')!='rgba(0, 0, 0, 0)'){
                        str+=$(this).text();
                    }
                });
                if(str==''){
                    return false;
                }
                $(this).parent().find('.but').removeClass('but');
                title++;
                var answer= $(this).parent().next().children().find('.answer').text().toUpperCase();
                answer=answer.replace(/\s/g, "")
                if(str!=answer){
                    $(this).parent().next().append("<span style='color: red'>×</span>");
                    falseAnswer++;
                    id.push($(this).parent().next().next().attr('id'));//題目id
//                                alert(id);

                }
                else{
                    $(this).parent().next().append("<span style='color: green'>√</span>");
                    cid.push($(this).parent().next().next().attr('id')) ;//題目id
                    //            alert(cid);
                }
                $(this).hide();
                $(this).parent().next().show();//显示解析
                $(this).parent().next().next().show();//显示下一题
                //        $('.but').parent().parent().find('.but').removeClass('but');
            })
            //交卷
            function sub(){
                console.log(id);
                console.log(cid)
                $.ajax({
                    url:"https://newapp.icandrive.cn/api/title.php",
                    data:{token:token,wrong:id,right:cid},
                    dataType:'json',
                    type:'post',
                    success: function (data) {
                        console.log(data)
                        if(data.status==200){
                            console.log(titleID);
                            var index=title-falseAnswer; //错误率 保留两位小数
                            layer.msg("本次得分为:"+index,function(){
                               history.back();
                            },5000);
                        }
                    },
                    error: function () {
                        console.log('cuowu')
                    }
                })

            }
        </script>

        <script>
            document.addEventListener("plusready", function() {
                // 注册返回按键事件
                plus.key.addEventListener('backbutton', function() {
                    window.history.back();
                }, false);
                //此处false代表不退出页面，如果为true回退到上一个一面
            });
        </script>
    </body>
</html>
